<%@ page language="java" pageEncoding="UTF-8"%>

<div id="menuContent" class="menuContent" style="display:none; position: absolute;">
	<ul id="orgTree" class="ztree" style="margin-top:0; width:160px;"></ul>
</div>
 <link rel="stylesheet" href="${base }/css/zTreeStyle/zTreeStyle.css" type="text/css"/>
<script type="text/javascript" src="${base }/js/tree/jquery.ztree.core-3.0.js"></script>
<script type="text/javascript" src="${base }/js/tree/jquery.ztree.excheck-3.0.js"></script>
<script type="text/javascript">
var orgTree;
var nameObject;
var idObject;
var ckeckEnable=false;
var muliSelect=false;
var checkParent=true;
function cickFunction(e, treeId, treeNode) {
	orgTree = $.fn.zTree.getZTreeObj("orgTree");
	if(ckeckEnable)
	{
	nodes=orgTree.getCheckedNodes(true);
	}
else
	{
	nodes=  orgTree.getSelectedNodes();
	}
  var 	values = "";
  var ids="";
	for (var i=0, l=nodes.length; i<l; i++) {
	 
		values += nodes[i].name + ",";
		ids+= nodes[i].id + ",";
		 
	}
	if (values.length > 0 ) values = values.substring(0, values.length-1);
	if (ids.length > 0 ) ids = ids.substring(0, ids.length-1);
	nameObject.attr("value", values);
	idObject.attr("value", ids);
}
function beforeClick(treeId, treeNode) {
	if(!checkParent)
		{
		return !treeNode.isParent;
		}
}
function hideMenu() {
	$("#menuContent").fadeOut("fast");
	$("body").unbind("mousedown", onBodyDown);
}
function onBodyDown(event) {
	if (!(event.target.id == "menuBtn" || event.target.id == "menuContent" || $(event.target).parents("#menuContent").length>0)) {
		hideMenu();
	}
}
 function showTree(dataurl)
 {
	 var setting = {
			 	view: {selectedMulti: muliSelect},
				check: {enable: ckeckEnable},	
				data: {simpleData: {enable: true}} ,
				async: {enable: true,url: dataurl},
				callback: {beforeClick:beforeClick,
					onClick: cickFunction,onCheck:cickFunction}
			              };
		var zNodes = ""; 
		//没有初始化的时候初始化一次
		if(!orgTree){
			orgTree=	$.fn.zTree.init($("#orgTree"), setting, zNodes);
			}
		var nameOffset = nameObject.offset();
		$("#menuContent").css({left:nameOffset.left + "px", top:nameOffset.top + nameObject.outerHeight() + "px"}).slideDown("fast");
		$("body").bind("mousedown", onBodyDown);
}
</script>